package cool.taomu.toolkit.demo.stock.listener

import cool.taomu.toolkit.demo.stock.entity.StockHistory
import cool.taomu.toolkit.demo.stock.listener.entity.StockDataEvent

class RsiSignalListener extends BaseSignalListener {

	override void process(StockDataEvent event) {
		var data = event.getHistoryList();
		var code = event.getStockCode();

		for (var int i = 2; i < data.size(); i++) {
			var StockHistory c = data.get(i);
			var StockHistory p = data.get(i - 1);
			var StockHistory b = data.get(i - 2);

			if (isBottom(c, p, b)) {
				var double cv = c.rsi6;
				var double pv = p.rsi6;
				if (cv > pv && pv <= b.rsi6) {
					saveSignal(code, c.getDate(), "RSI", "BUY", c.getClose(), cv);
				}
			}

			if (isTop(c, p, b)) {
				var double cv = c.rsi6;
				var double pv = p.rsi6;
				if (cv < pv && pv >= b.rsi6) {
					saveSignal(code, c.getDate(), "RSI", "SELL", c.getClose(), cv);
				}
			}
		}
	}

}
